Skip to content

perf(legacy): skip the native bounds read when setBounds gets a full Rect - #607

Open
palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/legacy-setbounds-full-rect
Open

palmoni5 wants to merge 1 commit into
leanflutter:mainfrom
palmoni5:upstream/legacy-setbounds-full-rect

Conversation

@palmoni5

Copy link
Copy Markdown

Problem

WindowManager.setBounds in the 0.5.x-compatible legacy API always read the window's current bounds through nativeapi (a synchronous FFI call) before applying new ones. It did this even when the caller passed a full Rect, so none of the values it read were used. Apps that restore or move the window with a full Rect pay for that extra native round trip on every call.

Change

Tests

New test/legacy_set_bounds_test.dart, with its own fake nativeapi.Window that counts bounds reads. It checks that:

  • a full Rect is applied with no bounds read;
  • position-only and size-only updates still read the omitted values;
  • a full Rect wins over position/size;
  • animate: true falls back to a plain set;
  • an empty request does nothing.

dart format, flutter analyze (package and example) and flutter test all pass locally.

…Rect

setBounds read the window's current bounds through nativeapi before every
call, even when the caller passed a full Rect and none of the current values
were used. Only read them when position or size is partial.

Adds debugBindWindow (same hook as the sibling legacy PRs) so the bridge can
be tested against a Dart fake window.
mockturtl added a commit to mockturtl/window_manager that referenced this pull request Nov 17, 2026
setPosition called setBounds(null, position: ...). setBounds reads
window.bounds, replaces the position and writes the whole rectangle back.
After a setSize call, the window manager applies the new size a few
milliseconds later. Until then, window.bounds returns the old size, so
setBounds wrote the old size back and cancelled the new one. On Linux
(X11), this broke setAlignment, setPosition and center after setSize.

When animate is false, move only the position. The animated path does not
change.

Add WindowManager.debugTarget (visible for testing), so that a test can
replace the native window with a fake. Add tests for setPosition. With the
old code, the three tests for animate false fail. With the fix, all five
pass.

debugTarget is a temporary test hook. The open PR
leanflutter#607 adds debugBindWindow(window) for the same
job. When that PR merges, the tests will use debugBindWindow and
debugTarget will go away. The open PR leanflutter#606 also
changes the _target getter, so a conflict with debugTarget is likely.

Checked by hand on Linux (X11, Cinnamon 6.6.9 with Muffin 6.6.3). Not
tested on macOS, Windows or Wayland.

Refs libnativeapi/nativeapi#37

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
mockturtl added a commit to mockturtl/window_manager that referenced this pull request Nov 17, 2026
Replace the temporary WindowManager.debugTarget setter with
debugBindWindow(window). The open PR leanflutter#607 adds
debugBindWindow for the same job.

This commit needs leanflutter#607. Without leanflutter#607, the tests do not compile. Merge leanflutter#607
before this commit. The previous commit stands alone, and its tests pass
with debugTarget.

The tests check the same behavior as before. I ran them with leanflutter#607 applied
on top of this branch. The five tests of legacy_set_position_test.dart
pass, and so do the five tests of leanflutter#607. With setPosition reverted, exactly
the three tests for animate false fail. Tested on Linux (X11) only.

Refs libnativeapi/nativeapi#37

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant